//
// Created by wze-zero on 2024/10/20.
//
#include <iostream>

using namespace std;

int change(long num) {
    long sum = 0;
    while (num % 10 || num / 10) {
        sum += num % 10;
        num /= 10;
    }
    return sum;
}

int main() {
    long num;
    cin >> num;
    while (num / 10) {
        num = change(num);
    }
    cout << num << endl;
    return 0;
}